package ONLINE_EXAM;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class shell2 {
    public static void main(String[] args) throws IOException {
        //BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int[] nums = new int[n];
            for (int i = 0; i < n; i++) {
                nums[i] = (sc.nextInt());
            }

           int pivot = nums[0];
            int mount = 1;
            HashMap<Integer,Integer> map = new HashMap<>();
            for (int i =1;i<nums.length;i++){
               if (nums[i]>= pivot){
                   pivot = nums[i];
                   map.put(i,nums[i]);
                   mount++;
               }
            }
            
            int[][] bucket = new int[mount][n];
            int[] cnt = new int[mount];
            int b =0;
            for (int piv:map.values()){
                bucket[b][0] = piv;
                cnt[b] = 1;
                b++;
                
            }
      
        for (int i = 0; i < nums.length; i++) {
            if (map.containsKey(i)){
                continue;
            }
            
            for (int j = 0;j<mount;j++){
                //找到对应的桶
                if (nums[i] < bucket[j][cnt[j]]){
                    cnt[j]++;
                    bucket[j][cnt[j]] = nums[i];
                }
            }
            
        }




    }
}
